package cn.itsource.pethome.org.service.impl;

import cn.itsource.pethome.basic.service.impl.BaseServiceImpl;
import cn.itsource.pethome.org.domain.Employee;
import cn.itsource.pethome.org.mapper.EmployeeMapper;
import cn.itsource.pethome.org.service.IEmployeeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 员工service实现类  继承service公共实现类
 */
@Service
public class EmployeeServiceImpl extends BaseServiceImpl<Employee> implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    /**
     * 后台用户登录
     *
     * @param employee
     * @return
     */
    @Override
    public Employee login(Employee employee) {
        //验证用户名
        if (StringUtils.isEmpty(employee.getUsername())){
            throw new RuntimeException("用户名为空");
        }
        //验证密码
        if (StringUtils.isEmpty(employee.getPassword())){
            throw new RuntimeException("密码为空");
        }
        //先通过接收到用户名去查询
        Employee dbEmployee = employeeMapper.findByName(employee.getUsername());
        //判断用户名是否为空
        if (dbEmployee == null) {
            throw new RuntimeException("用户名不存在");
        }else {
            if (!dbEmployee.getPassword().equals(employee.getPassword())) {
                throw new RuntimeException("密码错误！！");
            }

        }
        return dbEmployee;
    }
}
